import java.util.HashSet;
import java.util.Set;

/**
 * @author 何杰
 * @version 1.0
 */
public class LengthOfLongestSubstring {
    public static void main(String[] args) {
        String str = "pwwkew";
        System.out.println(lengthOfLongestSubstring(str));
    }
    public static int lengthOfLongestSubstring(String s) {
        Set<Character> set = new HashSet<>();
        int n = s.length();
        int rk = -1, ans = 0;
        for (int i = 0; i < n; i++) {
            if(i != 0) {
                set.remove(s.charAt(i-1));
            }
            while(rk + 1 < n && !set.contains(s.charAt(rk+1))) {
                set.add(s.charAt(rk+1));
                ++rk;
            }
            ans = Math.max(ans, rk - i + 1);
        }
        return ans;
    }
}
